<template>
  <div>
    <el-container>
        <el-main>
            <el-row :gutter="20">
                <el-col :span="12" :offset="6">
                    <h3>
                        <span>个人设置</span>
                        <el-button type="default" class="settings-btn" plain @click="backHome">首页</el-button>
                    </h3>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="12" :offset="6">
                    <el-tabs v-model="activeName" class="settings-tab">
                        <el-tab-pane label="个人设置" name="first">
                            <el-col :span="12">
                                <el-form ref="form"  label-width="80px">
                                    <el-form-item label="昵称">
                                        <el-input placeholder="昵称" size="small" v-model="userInfo.nickName"></el-input>
                                    </el-form-item>
                                    <el-form-item label="邮箱">
                                        <el-input placeholder="邮箱" size="small" v-model="userInfo.email"></el-input>
                                    </el-form-item>
                                    <el-form-item label="个性签名">
                                        <el-input placeholder="个性签名" size="small" v-model="userInfo.signature"></el-input>
                                    </el-form-item>
                                    <el-form-item label="个人爱好">
                                        <el-checkbox-group v-model="userInfo.hobby">
                                        <el-checkbox label="打球" name="hobby"></el-checkbox>
                                        <el-checkbox label="看球" name="hobby"></el-checkbox>
                                        <el-checkbox label="踢球" name="hobby"></el-checkbox>
                                        <el-checkbox label="其他" name="hobby"></el-checkbox>
                                        </el-checkbox-group>
                                    </el-form-item>
                                    <el-form-item label="性别">
                                        <el-radio-group v-model="userInfo.sex">
                                        <el-radio label="man" name="sex">帅哥</el-radio>
                                        <el-radio label="woman" name="sex">美女</el-radio>
                                        </el-radio-group>
                                    </el-form-item>                            
                                    <el-form-item label="自我介绍">
                                        <el-input type="textarea" placeholder="说几句吧..." v-model="userInfo.description"></el-input>
                                    </el-form-item>
                                    <el-form-item>
                                        <el-button type="default" plain @click="profileSave">保存</el-button>
                                    </el-form-item>
                                </el-form>
                            </el-col>
                            <el-col :span="12">
                                <el-alert type="info" title="数据预览">
                                    {{ userInfo }}
                                </el-alert>
                            </el-col>
                            
                        </el-tab-pane>
                        <el-tab-pane label="头像设置" name="second" style="padding-top:40px;">
                            <el-row :gutter="20">
                                <el-col :span="10">
                                    <el-upload
                                        action="https://jsonplaceholder.typicode.com/posts/"
                                        list-type="picture-card"
                                        :on-preview="handlePictureCardPreview"
                                        :on-remove="handleRemove">
                                        <i class="el-icon-plus"></i>
                                    </el-upload>
                                    <el-dialog :visible.sync="dialogVisible" size="tiny">
                                        <img width="100%" :src="dialogImageUrl" alt="">
                                    </el-dialog>                                   
                                </el-col>
                                <el-col :span="10">
                                    <br/>
                                    <img src="../../assets/avatar.png" alt="" class="user-avatar">
                                    <img src="../../assets/avatar.png" alt="" class="user-avatar" style="width:80px;height:80px;">
                                    <img src="../../assets/avatar.png" alt="" class="user-avatar" style="width:40px;height:40px;">   
                                </el-col>
                            </el-row>
                            <br/>
                            <el-button type="dafault" @click="setAvatar">保存</el-button>
                        </el-tab-pane>
                    </el-tabs>
                </el-col>
            </el-row>
        </el-main>
    </el-container>
  </div>
</template>

<script>
    export default {
        name: 'Profile',
        data() {
            return {
                activeName: 'first',
                userInfo: {
                    nickName: 'Stilly',
                    email: '',
                    signature: '',
                    hobby: [],
                    description: ''
                },
                dialogImageUrl: '',
                dialogVisible: false
            }
        },
        methods: {
            profileSave() {
                //这里可以发送axios请求跟api交流信息后，提示信息
                console.log(this.userInfo)
                this.$message.success('错了哦，这是一条错误消息')
            },
            setAvatar() {
                this.$alert('确定更换头像吗?', '系统提示', {
                    confirmButtonText: '确认',
                    callback: action => {
                        this.$message.success({
                            'message': '头像更新成功'
                        })
                    }
                });
            },
            backHome() {
                this.$router.push({name: 'home'})
            },
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },
            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.url;
                this.dialogVisible = true;
            }            
        }
    }
</script>
<style scoped>

 body{
    background: red
 }
  ul,li{
    list-style-type: none
  }
  .el-header {
    background-color: #F2F6FC;
    color: #333;
    line-height: 60px;
  }
  
  .el-aside {
    color: #333;
  }
  .settings-btn{
      float: right
  }
  .white-bg{
      background: #FFF
  }
  h3{
      margin-bottom: 40px;
      color: #34495E
  }
  .settings-tab{
      /* padding: 40px 0; */
  }
  .user-avatar{
      height: 120px;
      width: 120px;
      border-radius:5px;
      margin-right: 15px;
  }
</style>